Remove komutu hatasi
Merhaba yapmis oldugum projemde personel menusunde musteri sil komutunu calistirdigimda islemi algilamiyor sizden ricam yardimci olurmusunuz?
USER CLASS
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.io.PrintStream;
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;
import java.util.logging.Level;
import java.util.logging.Logger;
public class User extends Money implements Login{
private String userName;
private String passWord;
File f=new File("C:\\Users\\efeadel\\Documents\\NetBeansProjects\\BankApp\\database.txt");
@Override
public boolean check(String userName , String passWord) {
if(userName == null ? passWord == null : userName.equals(passWord)){
System.out.println("Username and password cannot be the same!!");
return false;
}
else{
try{
Scanner fileScan=new Scanner(f);
while(fileScan.hasNext()){
if(fileScan.next().equals(userName)){
if(fileScan.next().equals(passWord)){
return true;
}
}
else
{
fileScan.hasNextLine();
}
}
}catch(FileNotFoundException e){
System.out.println("File not found");
}
this.userName=null; //tekrar aynı degerlerin olmasini onlemek icin null yapıyoruz.
this.passWord=null;
System.err.println("You Have Wrong Login !!");
return false;
}
}
//Doğum günü tarihi hesap türü gibi şeyler buraya eklenebilir.
@Override
public void addUser(String userName , String passWord,float money) {
if(userName!=null&&passWord!=null){
try{
OutputStream os=new FileOutputStream(f,true);
PrintStream ps=new PrintStream(os);
ps.println(userName+" "+passWord+" "+money);
} catch (FileNotFoundException ex) {
System.err.println("Error User.addUser of method"+ex);
}
}
else {
System.err.println("You entered invalid information ... Username or password cannot be empty!!");
}
}
@Override
public boolean delUser(String userName) {
String line=null;
Scanner scan = null;
try {
scan = new Scanner(f);
} catch (FileNotFoundException ex) {
Logger.getLogger(User.class.getName()).log(Level.SEVERE, null, ex);
}
Scanner sc = null;
try {
sc = new Scanner(f);
} catch (FileNotFoundException ex) {
Logger.getLogger(User.class.getName()).log(Level.SEVERE, null, ex);
}
Set set= new HashSet();
while (scan.hasNextLine()) {
line = scan.nextLine();
if(set.add(line)) {
sc.hasNext(line+"\n");
}
}
sc.next();
return false;
}
@Override
public void reformation(String userName,String passWord,String newPassWord) {
if(newPassWord!=null && !newPassWord.equals(passWord))
{
try{
int numberoflines=0;
String satir=null;
Scanner scanner = new Scanner(f);
while(scanner.hasNextLine()){
numberoflines++;
satir=scanner.nextLine();
}
String [] database = new String[numberoflines];
scanner.close();
scanner=new Scanner(f);
for(int i=0;i<numberoflines;i++){
database[i]=scanner.nextLine();
}
scanner.close();
FileOutputStream os=new FileOutputStream(f,false);
PrintStream ps=new PrintStream(os);
for(int i=0;i<numberoflines;i++){
if(database[i].contains(userName)){
database[i]=database[i].replace(String.valueOf(passWord),String.valueOf(newPassWord));
}
ps.println(database[i]);
}
System.out.println(userName+" New Password+");
os.close();
ps.close();
}catch(FileNotFoundException e){
System.out.println("Error reformation of method"+e);
}catch(NullPointerException | IOException a){
System.out.println("Error reformation of method "+a);
}
}
else
System.out.println("The password cannot be empty or the same !!");
}
@Override //Overload yaptığım metod Tek argüman alıyor.
public boolean check(String userName){
try{
Scanner scan=new Scanner(f);
while(scan.hasNext()){
if(scan.next().equals(userName)){
return true ;
}else{
scan.nextLine();
}
}
}catch(FileNotFoundException e){
System.out.println("Error in user chech single parameter method "+e);
}
return false;
}
public String getUserName() {
return userName;
}
public void setUserName(String userName) {
this.userName = userName;
}
public String getPassWord() {
return passWord;
}
public void setPassWord(String passWord) {
this.passWord = passWord;
}
}
BANK CLASS
import java.util.Scanner;
public class Bank {
public static void main(String[] args) {
Scanner scan=new Scanner(System.in);
User getUser=new User();
User PassWord=new User();
start:
while(true){
System.out.println("Welcome BANK YILDIRIM Application");
System.out.println("------------------");
System.out.println("Client Login 1 : ");
System.out.println("Employee 2 :");
switch(scan.nextInt()){
case 1:
System.out.print("Please Enter User Name");
getUser.setUserName(scan.next());
System.out.print("Please Enter Password :");
getUser.setPassWord(scan.next());
if(getUser.check(getUser.getUserName(),getUser.getPassWord())){
System.out.println("Login successful!!");
while(true){
//Menu oluşturma bölümü
System.out.println("Welcome Client Page");
System.out.println("------------------");
System.out.println("Deposit Money 1 :");
System.out.println("Withdraw Money 2 :");
System.out.println("Change Password 3 :");
System.out.println("Exit 4 :");
System.out.println("Choose ...");
switch(scan.nextInt()){
case 1:
System.out.print("Your Current Balance :");
getUser.showMoney(getUser.getUserName(),getUser.getPassWord());
System.out.print("Enter the amount of money you want to add (Number Only) :");
float newMoney=scan.nextFloat();
getUser.addMoney(getUser.getUserName(),getUser.userMoney,getUser.userMoney+newMoney);
break;
case 2:
System.out.print("Your Current Balance :");
getUser.showMoney(getUser.getUserName(),getUser.getPassWord());
System.out.print("Enter the amount of money you want to withdraw :");
float getMoney=scan.nextFloat();
if(getMoney>getUser.userMoney){
System.err.println("You do not have sufficient balance!");
break;
}
else{
getUser.getMoney(getUser.getUserName(), getUser.userMoney,getUser.userMoney-getMoney);
}
break;
case 3:
System.out.print("Enter your current password:");
if(scan.next().equals(getUser.getPassWord())){
System.out.print("Enter your new password:");
String newPassWord=scan.next();
System.out.print("Repeat new password :");
if(newPassWord.equals(scan.next())){
getUser.reformation(getUser.getUserName(),getUser.getPassWord(), newPassWord);
}
else {
System.err.println("Passwords do not match!!");
}
}
else
System.err.println("Incorrect password entered !!");
break;
case 4:
System.out.println("You have logged out!!");
break start;
default:
System.err.println("You made a wrong selection :");
break;
}
}
}
break;
case 2:
while(true){
//Menu oluşturma bölümü
System.out.println("Welcome Employee Page");
System.out.println("------------------");
System.out.println("Add New CLient 1 :");
System.out.println("Delete Client 2");
System.out.println("Exit 3 :");
System.out.println("Choose ...");
switch(scan.nextInt()){
case 1:
String userName;
System.out.print("Enter a client name:");
userName=scan.next();
while(getUser.check(userName)){
System.err.println("Such a client name already exists !!");
System.out.print("Enter another client name :");
userName=scan.next();
}
System.out.print("Enter a password:");
String passWord=scan.next();
System.out.print("Enter the amount of money to add:");
float money=scan.nextFloat();
getUser.addUser(userName, passWord, money);
System.out.println("Created successfully..");
break;
case 2:
System.out.println("Enter a client name");
userName=scan.next();
getUser.delUser(userName);
System.out.println("Delete Successfully");
break;
case 3:
System.out.println("You have logged out!!");
break start;
default:
System.err.println("You made a wrong selection :");
break;
}}}}}}
LOGIN CLASS
public interface Login{
boolean check(String userName);
boolean check(String userName,String passWord);
void addUser(String userName,String passWord,float money);
boolean delUser(String userName);
void reformation(String userName,String passWord,String newPassWord);
}